class Backend::BaseController < ManagementBaseController
  # check_authorization

  before_action :logged_in?
  before_action :set_paper_trail_whodunnit
  layout 'backend'

  helper_method :current_admin
  # helper_method :current_user

  # 重写can的获取ability方法
  def current_ability
    @current_ability ||= Ability.new(current_admin)
  end



  protected

  def user_for_paper_trail
    "管理员：#{current_admin.name}" if current_admin
  end

  def info_for_paper_trail
    {ip: request.remote_ip}
  end

  def logged_in?
    if session[:current_admin_id].present?
      return true
    else
      redirect_to backend_login_path
    end
  end

  def current_admin
    @current_admin = AdminUser.first
    # @current_administrator ||= AdminUser.find_by id: session[:current_admin_id]
  end

end
